//const controllers = require('../../controllers/controllerIndex.js').controller;
const app = getApp();
const controllers = app.controllers;
const controller=require("../../controllers/Controller").controller
Page({
  data: {
    dataList:[],
    startTime:"2020-01-01",
    endTime:"2020-01-01",
    state:"",
    stateList:["全部","未完结","已完结"],
    selectState:"全部",
    userId:''
  },
  onLoad: function (options) {
    if(options.userId){
      this.setData({
        userId:options.userId
      })
    }
    this.defaultGetList()
  },
  defaultGetList(){
    let searchKey = this.data.searchKey||"";
    let that = this; 
      if(this.data.userId){
        controller.checkLookVIPlist({
          sessionId: wx.getStorageSync('token'),
          shopId:wx.getStorageSync('shopId'),
          accountId: this.data.userId,
        }).then(res =>{
          that.setData({
            dataList:res.data
           });
        });
      }else{
        controllers.checkVIPlist({
          sessionId: wx.getStorageSync('token'),
          shopId:wx.getStorageSync('shopId'),
          mobile: searchKey,
        }).then(res =>{
          that.setData({
            dataList:res.data
           });
        });
      }
  },
  getList: function () {
    let searchKey = this.data.searchKey||"";
    let that = this; 
      controllers.checkVIPlist({
        sessionId: wx.getStorageSync('token'),
        shopId:wx.getStorageSync('shopId'),
        mobile: searchKey,
        state:this.data.state,
        startTime:this.data.startTime,
        endTime:this.data.endTime
      }).then(res =>{
        that.setData({
          dataList:res.data
         });
      });
  },
  openCard() {
    wx.navigateTo({
      url: '../OpenCard/OpenCard',
    })
  },
  
  searchInput: function (e) {//搜索输入框
    this.setData({
      searchKey:e.detail.value
    });
  },
  onSearch: function (e) {//搜索
    this.getList();
  }, 
  toUrl(e) {
    var d = e.currentTarget.dataset;
    let url = d.url;
    console.info(url);
    wx.navigateTo({
      url: url
    });
  },

  //切换搜索状态
  bindStateChange(e){
    let index=e.detail.value;
    if(index==0){
      this.setData({
        selectState:"全部",
        state:""
      })
    }else if(index==1){
      this.setData({
        selectState:"未完结",
        state:1
      })
    }else{
      this.setData({
        selectState:"已完结",
        state:0
      })
    }
  },

  //改变开始时间
  bindDateChange1(e){
    this.setData({
      startTime:e.detail.value
    })
  },

  //改变结束时间
  bindDateChange2(e){
    this.setData({
      endTime:e.detail.value
    })
  }

})